package com.mt.mtyx.common.utils.generate.generate.config;

import com.mt.mtyx.common.utils.generate.generate.code.GenerateMethod;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

/**
 * @author WMT
 * @Date 2023/5/26 17:27
 */
public class MapperCodeConfig {

    /**
     * mapper名称
     */
    private String mapperName;

    /**
     * mapper Xml名称
     */
    private String mapperXmlName;

    /**
     * 是否开启字段填充
     */
    private boolean enableFieldMapper;

    /**
     * mapper 格式化
     */
    private String mapperFormat = "%sMapper";

    /**
     * mapper Xml 格式化
     */
    private String mapperXmlFormat = "%sMapper";

    /**
     * 是否开启mapper注解
     */
    private boolean enableMapper;

    /**
     * mapper注解的全包名
     */
    private String mapperAnna = "org.apache.ibatis.annotations.Mapper";

    /**
     * 是否开启mybatis-plus
     */
    private boolean enableMapperPlus;

    /**
     * baseMapper 全包名;
     */
    private String mapperPlus = "com.baomidou.mybatisplus.core.mapper.BaseMapper";

    /**
     * 父类包名
     */
    private String supperCLass;

    /**
     * mapper 导包
     */
    private Set<String> importPackage;

    /**
     * 生成的方法隐射 如果要忽略某个方法 则将他的value值设置为null即可
     */
    private final Map<String, GenerateMethod> method;

    {
        method = new LinkedHashMap<>();
        method.put("INSERT", new GenerateMethod("INSERT", null, "insert%s", null, null, null, null, null));
        method.put("DELETE", new GenerateMethod("DELETE", null, "delete%s", null, null, null, null, null));
        method.put("UPDATE", new GenerateMethod("UPDATE", null, "update%s", null, null, null, null, null));
        method.put("COUNT", new GenerateMethod("COUNT", null, "select%sCount", null, null, null, null, null));
        method.put("LIST", new GenerateMethod("LIST", null, "select%sList", null, null, null, null, null));
        method.put("ONE", new GenerateMethod("ONE", null, "selectOne%s", null, null, null, null, null));
    }

    public String getMapperName() {
        return mapperName;
    }

    public MapperCodeConfig mapperName(String mapperName) {
        this.mapperName = mapperName;
        return this;
    }

    public String getMapperXmlName() {
        return mapperXmlName;
    }

    public MapperCodeConfig mapperXmlName(String mapperXmlName) {
        this.mapperXmlName = mapperXmlName;
        return this;
    }

    public boolean isEnableFieldMapper() {
        return enableFieldMapper;
    }

    public MapperCodeConfig enableFieldMapper(boolean enableFieldMapper) {
        this.enableFieldMapper = enableFieldMapper;
        return this;
    }

    public String getMapperFormat() {
        return mapperFormat;
    }

    public MapperCodeConfig mapperFormat(String mapperFormat) {
        this.mapperFormat = mapperFormat;
        return this;
    }

    public String getMapperXmlFormat() {
        return mapperXmlFormat;
    }

    public MapperCodeConfig mapperXmlFormat(String mapperXmlFormat) {
        this.mapperXmlFormat = mapperXmlFormat;
        return this;
    }

    public String getSupperCLass() {
        return supperCLass;
    }

    public MapperCodeConfig supperCLass(String supperCLass) {
        this.supperCLass = supperCLass;
        return this;
    }

    public MapperCodeConfig importPackage(Set<String> importPackage) {
        this.importPackage = importPackage;
        return this;
    }

    public Set<String> getImportPackage() {
        return importPackage;
    }

    public boolean isEnableMapperPlus() {
        return enableMapperPlus;
    }

    public MapperCodeConfig enableMapperPlus(boolean enableMapperPlus) {
        this.enableMapperPlus = enableMapperPlus;
        return this;
    }

    public String getMapperPlus() {
        return mapperPlus;
    }

    public MapperCodeConfig mapperPlus(String mapperPlus) {
        this.mapperPlus = mapperPlus;
        return this;
    }

    public boolean isEnableMapper() {
        return enableMapper;
    }

    public MapperCodeConfig enableMapper(boolean enableMapper) {
        this.enableMapper = enableMapper;
        return this;
    }

    public String getMapperAnna() {
        return mapperAnna;
    }

    public MapperCodeConfig mapperAnna(String mapperAnna) {
        this.mapperAnna = mapperAnna;
        return this;
    }

    public Map<String, GenerateMethod> getMethod() {
        return method;
    }


    public MapperCodeConfig methodMap(Consumer<Map<String, GenerateMethod>> methodMap) {
        methodMap.accept(method);
        return this;
    }
}
